/**
 * @(#)searchInterface.java
 *
 *
 * @author 
 * @version 1.00 2010/2/20
 */
package drops.gui;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;

public class SearchPanel extends JPanel implements ItemListener{

	JComboBox tableChooserDropDown;
	SearchPatientPanel searchPatientPanel;
	SearchTransactionPanel searchTransactionPanel;
	MainFrame mainFrame;
	ComboBoxModel tableChooserModel;
	
    public SearchPanel(MainFrame mainFrame) {
    	super();
    	this.mainFrame = mainFrame;
    	String tables[] = {"Patient", "Transaction"};
    	tableChooserModel = new DefaultComboBoxModel(tables);
    	tableChooserDropDown = new JComboBox(tableChooserModel);
    	tableChooserDropDown.addItemListener(this);
    	searchPatientPanel = new SearchPatientPanel(mainFrame);
    	searchTransactionPanel = new SearchTransactionPanel(mainFrame);
    	searchPatientPanel.setVisible(true);
		searchTransactionPanel.setVisible(false);
		add(tableChooserDropDown);
		add(searchPatientPanel);
		add(searchTransactionPanel);
    }

    private void updateTable() {
		String choose = tableChooserModel.getSelectedItem().toString();
		if (choose=="Patient") {
			if (!searchPatientPanel.isVisible()) {
				searchPatientPanel.setVisible(true);
				searchTransactionPanel.setVisible(false);
			}
		}
		else if (choose=="Transaction") {
			if (!searchTransactionPanel.isVisible()) {
				searchPatientPanel.setVisible(false);
				searchTransactionPanel.setVisible(true);
			}
		}
    }
    
	@Override
	public void itemStateChanged(ItemEvent arg0) {
		// TODO Auto-generated method stub
		updateTable();
	}
}